﻿/*
    Copyright 2010, 2011 Eric Wong
	contact@optimalcycling.com
	http://www.optimalcycling.com
	Optimal Cycling - Advanced power pacing program for cyclists
	
	This file is part of Optimal Cycling.

    Optimal Cycling is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Optimal Cycling is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with Optimal Cycling.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef __OPENCL_VERSION__
	#include "Interpolate.h"
#endif

//// Required dataCount >= 1
//inline real InterpolateBinary(const real valFind, __global const real* independentData, __global const real* dependentData, 
//							  const sizeT dataCount)
//{
//    if (independentData[0] >= valFind)
//    {
//        return dependentData[0];
//    }
//    else if (independentData[dataCount - 1] <= valFind)
//    {
//        return dependentData[dataCount - 1];
//    }
//
//    sizeT left = 0;
//    sizeT right = dataCount - 1;
//
//    while (right - left > 1)
//    {
//        sizeT indexer = left + ((right - left) / 2);
//
//        if (independentData[indexer] < valFind)
//        {
//            left = indexer;
//        }
//        else
//        {
//            right = indexer;
//        }
//    }
//
//	real valDiff = independentData[right] - independentData[left];
//    if (valDiff < SMALL_REAL)
//        return dependentData[left];
//    else
//        return mix(dependentData[left], dependentData[right], (valFind - independentData[left]) / valDiff);
//}



//inline real4 InterpolateBinaryReal4(const real valFind, __global const real4* data, const sizeT dataCount)
//{
//    if (data[0].s0 >= valFind)
//    {
//        return data[0];
//    }
//    else if (data[dataCount - 1].s0 <= valFind)
//    {
//        return data[dataCount - 1];
//    }
//
//    sizeT left = 0;
//    sizeT right = dataCount - 1;
//
//    while (right - left > 1)
//    {
//        sizeT indexer = left + ((right - left) / 2);
//
//        if (data[indexer].s0 < valFind)
//        {
//            left = indexer;
//        }
//        else
//        {
//            right = indexer;
//        }
//    }
//
//	real valDiff = data[right].s0 - data[left].s0;
//    if (valDiff < SMALL_REAL)
//        return data[left];
//    else
//	{
//		real controlVal = (valFind - data[left].s0) / valDiff;
//		real4 controlValVec4 = {controlVal, controlVal, controlVal, controlVal};
//        return mix(data[left], data[right], controlValVec4);
//	}
//}

//inline real InterpolateBinaryExReal(const real valFind, __global const real * independentData, const sizeT startIndex,
//							  __global const real * dependentData, const sizeT dataCount)
//{
//    if (independentData[0] >= valFind)
//    {
//        return dependentData[startIndex];
//    }
//    else if (independentData[dataCount - 1] <= valFind)
//    {
//        return dependentData[startIndex + dataCount - 1];
//    }
//
//    sizeT left = 0;
//    sizeT right = dataCount - 1;
//
//    while (right - left > 1)
//    {
//        sizeT indexer = left + ((right - left) / 2);
//
//        if (independentData[indexer] < valFind)
//        {
//            left = indexer;
//        }
//        else
//        {
//            right = indexer;
//        }
//    }
//
//	real valDiff = independentData[right] - independentData[left];
//    if (valDiff < SMALL_REAL)
//        return dependentData[startIndex + left];
//    else
//        return mix(dependentData[startIndex + left], dependentData[startIndex + right], 
//			(valFind - independentData[left]) / valDiff);
//}







